import java.util.ArrayList;
import java.util.List;

public class Solution1238 {

    List<Integer> ans;

    public List<Integer> circularPermutation(int n, int start) {
        List<Integer> list=new ArrayList<>();
        list.add(start);
        boolean[] visit=new boolean[1<<n];
        visit[start]=true;
        dfs(list,visit,1,n);
        return ans;
    }

    private void dfs(List<Integer> list, boolean[] visit, int k,int n) {
        if (k==visit.length){
            if (valid(list.get(list.size()-1),list.get(0))){
                ans=new ArrayList<>(list);
            }
            return;
        }
        if (ans!=null){
            return;
        }
        int p=list.get(list.size()-1);
        for (int i=0;i<n;i++){
            int t=p^(1<<i);
            if (!visit[t] && valid(p,t)){
                list.add(t);
                visit[t]=true;
                dfs(list,visit,k+1,n);
                visit[t]=false;
                list.remove(list.size()-1);
            }
        }
    }

    private boolean valid(int a, int b) {
        return Integer.bitCount(a^b)==1;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1238().circularPermutation(2,3));
    }
}
